<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="ThemeBucket">
    <link rel="shortcut icon" href="#" type="image/png">

    <title>出库管理</title>

    <!--data table-->
    <link rel="stylesheet" href="js/data-tables/DT_bootstrap.css" />

    <link href="css/style.css" rel="stylesheet">
    <link href="css/style-responsive.css" rel="stylesheet">

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
    <script src="js/html5shiv.js"></script>
    <script src="js/respond.min.js"></script>
    <![endif]-->

    <style type="text/css">
        #all_light,#all_light_cu { /*整个弹窗的页面*/
            opacity: 0.8; /*透明度*/
            width: 100%; /*宽度*/
            height: 2300px; /*高度，不能百分百*/
            background: #000; /*背景色*/
            position: absolute;
            top: 0;
            left: 0; /*定位*/
            display: none; /*隐藏*/
            z-index: 2; /*覆盖*/
        }
        #contes,#contes_cu { /* 弹框的页面*/
            width: 500px; /*宽度*/
            height: 500px; /*高度*/
            background: #fff; /*背景色*/
            display: none; /*隐藏*/
            z-index: 2; /*覆盖*/
            position: absolute;
            top: 100px;
            left: 400px; /* 定位*/
        }
        input{
            margin-bottom: 10px;
        }
    </style>

</head>

<body class="sticky-header">


<!--  弹框的div==================================================================================== -->
<div id="contes" style="">
    <div style="width:500px;height:40px;">
        <hr>
        <h1> ==========出库==========</h1>
        <form style=" margin-left: 100px;" id="dataform">
            <input type="hidden" id="id" name="id">
            货品选择   :  <input id="name" type="text" name="name" list="goodslist" placeholder="请选择货品"><br>
            <datalist id="goodslist">

            </datalist>
            出库数量   :  <input type="text" value="" id="sum"  name="sum"><br>
            选择仓库   :  <input id="wid" type="text" name="wid" list="clist" placeholder="请选择仓库"><br>
            <datalist id="clist">

            </datalist>

            部门选择    :<input id="dept" type="text" name="dept" list="slist" placeholder="请选择部门"><br>
            <datalist id="slist"></datalist>

            <div id="su_div">
                客户选择  :<input id="customer" type="text" name="customer" list="klist" placeholder="请选择客户"><br>
                <datalist id="klist"></datalist>
            </div>
            <button type="submit" onclick="submithuoform()">提交</button>
            <button type="button" onclick="cancel()">取消</button>

        </form>
        <h1> ==========出库==========</h1>
    </div>
</div>
<div id="all_light">
</div>
<!--  弹框的div==================================================================================== -->


<!--  客户弹框的div==================================================================================== -->
<div id="contes_cu" style="">
    <div style="width:500px;height:40px;">
        <hr>

        <h1> ==========客户信息==========</h1>
        <form style=" margin-left: 100px;" id="dataform_cu">
            <input type="hidden" id="cuid" name="id">

            客户名字   :  <input type="text" value="" id="cuname"  name="name"><br>
            客户邮箱   :  <input type="text" value="" id="cuemail"  name="email"><br>
            客户号码   :  <input type="text" value="" id="cuphone"  name="phone"><br>
            客户地址   :  <input type="text" value="" id="cuaddr"  name="addr"><br>

            <button type="submit" onclick="submitcuform()">提交</button>
            <button type="button" onclick="cancelcu()">取消</button>

        </form>
        <h1> ==========客户信息==========</h1>
    </div>
</div>
<div id="all_light_cu">
</div>
<!--  客户弹框的div==================================================================================== -->

<section>
    <!-- left side start-->
    <script src="left.js"></script>
    <!-- left side end-->

    <!-- main content start-->
    <div class="main-content" >

        <!-- header section start-->
        <div class="header-section">

            <!--toggle button start-->
            <a class="toggle-btn"><i class="fa fa-bars"></i></a>
            <!--toggle button end-->


        </div>
        <!-- header section end-->

        <!-- page heading start-->
        <div class="page-heading">
            <h3>
                出库管理
            </h3>
            <ul class="breadcrumb">
                <li>
                    <a href="#">首页</a>
                </li>
                <li>
                    <a href="#">管理</a>
                </li>
                <li class="active"> 出库管理 </li>
            </ul>
        </div>
        <!-- page heading end-->

        <!--body wrapper start-->
        <div class="wrapper">
            <div class="row">
                <div class="col-sm-12">
                    <section class="panel">
                        <header class="panel-heading">
                            出库总信息
                            <br><label><input type="text"  id="queryMsg" placeholder="订单号查找" />
                            <button onclick="findBySearch()">搜索</button>
                        </label>

                            <span class="tools pull-right">
                        <a href="javascript:;" class="fa fa-chevron-down"></a>
                        <a href="javascript:;" class="fa fa-times"></a>
                     </span>
                        </header>
                        <div class="panel-body">
                            <div class="adv-table editable-table ">
                                <div class="clearfix">
                                    <div class="btn-group">
                                        <button  class="btn btn-primary" onclick="chu()">
                                            出库 <i class="fa fa-plus"></i>
                                        </button>
                                    </div>
                                    <div class="btn-group pull-right">
                                        <button class="btn btn-default dropdown-toggle" data-toggle="dropdown">Tools <i class="fa fa-angle-down"></i>
                                        </button>
                                        <ul class="dropdown-menu pull-right">
                                            <li><a href="#">Print</a></li>
                                            <li><a href="#">Save as PDF</a></li>
                                            <li><a href="#">Export to Excel</a></li>
                                        </ul>
                                    </div>
                                </div>
                                <div class="space15"></div>
                                <!-- 表格 -->
                                <table class="table table-striped table-hover table-bordered"
                                       id="editable-sample">
                                    <thead>
                                    <tr>
                                        <th prop="id">订单号</th>
                                        <th prop="name">货品分类名称</th>
                                        <th prop="sum">出库数量</th>
                                        <th prop="attr">货品属性</th>
                                        <th prop="perPrice">货品单价</th>
                                        <th prop="sumPrice">货品总价</th>
                                        <th prop="wid">所属仓库</th>
                                        <th prop="isPass">管理员是否批准</th>
                                        <th prop="supplierName">客户</th>
                                        <th prop="dept">处理部门</th>
                                        <th prop="updateTime">操作时间</th>
                                        <th>对本订单退货</th>
                                        <th>对本订单退货</th>
                                        <th>修改出库信息</th>
                                        <th>删除出库信息</th>
                                    </tr>
                                    </thead>

                                    <tbody id="newList">

                                    </tbody>
                                </table>
                            </div>

                        </div>
                        <div col-lg-6>

                            <div class="dataTables_paginate paging_bootstrap pagination">

                                <ul id="pagination">

                                </ul>
                            </div>
                        </div>
                    </section>
                </div>
            </div>
        </div>
        <!--body wrapper end-->



        <!--        退货管理-------------------------------------------->
        <div class="row">
            <div class="col-sm-12">
                <section class="panel">
                    <header class="panel-heading">
                        退货信息<br>
                        <span class="tools pull-right">
                <a href="javascript:;" class="fa fa-chevron-down"></a>
                <a href="javascript:;" class="fa fa-times"></a>

             </span>
                    </header>
                    <div class="panel-body">
                        <div class="adv-table">
                            <table class="display table table-bordered" id="hidden-table-info">
                                <thead>
                                <tr>
                                    <th prop="id">退货号</th>
                                    <th prop="reId">订单号</th>
                                    <th prop="attr">订单当前属性</th>
                                    <th prop="isPass">管理员是否批准</th>
                                    <th prop="updateTime">操作时间</th>
                                    <th prop="counts">退货数量</th>
                                    <th>取消退货</th>
                                </tr>
                                </thead>
                                <tbody id="tuihuolist">

                                </tbody>
                            </table>

                        </div>
                    </div>
                </section>
            </div>
        </div>
        <!--        退货管理------------------------------------------->


        <!--        客户管理-------------------------------------------->
        <div class="row">
            <div class="col-sm-12">
                <section class="panel">
                    <header class="panel-heading">
                        客户信息<br>
                        <span class="tools pull-right">
                <a href="javascript:;" class="fa fa-chevron-down"></a>
                <a href="javascript:;" class="fa fa-times"></a>

             </span>
                    </header>
                    <div class="panel-body">
                        <div class="adv-table">
                            <div class="btn-group">
                                <button  class="btn btn-primary" onclick="addcu()">
                                    添加客户 <i class="fa fa-plus"></i>
                                </button>

                            </div>
                            <table class="display table table-bordered" id="hidden-table-info-2">
                                <thead>
                                <tr>
                                    <th prop="id">客户号</th>
                                    <th prop="name">客户名字</th>
                                    <th prop="email">客户邮箱</th>
                                    <th prop="phone">客户号码</th>
                                    <th prop="addr">客户地址</th>
                                    <th>编辑</th>
                                    <th>删除</th>
                                </tr>
                                </thead>
                                <tbody id="culist">

                                </tbody>
                            </table>

                        </div>
                    </div>
                </section>
            </div>
        </div>
        <!--        客户管理------------------------------------------->


    </div>
    <!-- main content end-->
</section>

<!-- Placed js at the end of the document so the pages load faster -->
<script src="js/jquery-1.10.2.min.js"></script>
<script src="js/jquery-ui-1.9.2.custom.min.js"></script>
<script src="js/jquery-migrate-1.2.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/modernizr.min.js"></script>
<script src="js/jquery.nicescroll.js"></script>

<!--data table-->
<script type="text/javascript" src="js/data-tables/jquery.dataTables.js"></script>
<script type="text/javascript" src="js/data-tables/DT_bootstrap.js"></script>

<!--common scripts for all pages-->
<script src="js/scripts.js"></script>

<!--script for editable table-->
<script src="js/editable-table.js"></script>

<!-- END JAVASCRIPTS -->
<script src="orders.js"></script>
<script>
    window.onload=function (){
        var order;
        $.ajax({
            url:"/users/getOrder",
            type:"get",
            contentType:"application/json;charset=UTF8",
            dataType:"json",
            success:function (res){
                order=res;
                if(order==2){
                    order2();
                }
                if(order==3){
                    order3();
                }
            },
            error:function (){

            }
        })

        load();
    }
    var pagination={ //分页信息
        currentPage:1,
        pageSize:5,
        totalPage:10
    }

    //搜索框搜索
    function findBySearch() {
        var query=$("#queryMsg").val()

        gopage(1,query)
    }

    // 弹窗start
    function cancel(){
        document.getElementById('contes').style.display = 'none';
    }
    //展示下拉框
    function showSelect(goodslist,slist,clist,klist){
        $("#goodslist").empty();
        for(var i=0;i<goodslist.length;i++) {
            var tr="<option>"+goodslist[i].name+"-->id"+goodslist[i].id+"</option>";
            $("#goodslist").append(tr);
        }
        $("#slist").empty();
        for(var i=0;i<slist.length;i++) {
            var tr="<option>"+slist[i].name+"-->id"+slist[i].id+"</option>";
            $("#slist").append(tr);
        }
        $("#clist").empty();
        for(var i=0;i<clist.length;i++) {
            var tr="<option>"+clist[i].id+"-->id"+clist[i].id+"</option>";
            $("#clist").append(tr);
        }
        $("#klist").empty();
        for(var i=0;i<klist.length;i++) {
            var tr="<option>"+klist[i].name+"-->id"+klist[i].id+"</option>";
            $("#klist").append(tr);
        }
    }
    function jump(id) {//加载销售部门信息
        $.ajax({
            url:"/dept/getList/"+id,
            type:"get",
            contentType:"application/json;charset=UTF8",
            dataType:"json",
            success:function (res){
                if (res.success){
                    var goodsList=res.data.goodsList//赋值货品列表
                    var sl=res.data.deptList//赋值部门列表
                    var cl=res.data.wareHouseList//赋值仓库列表
                    var kl=res.data.customerList//赋值客户列表
                    showSelect(goodsList,sl,cl,kl);
                }
            },
            error:function (){

            }
        })
        document.getElementById('all_light');
        document.getElementById('contes').style.display = 'block';
    }
    //弹窗end
    function editJump() {
        document.getElementById('all_light');
        document.getElementById('contes').style.display = 'block';
    }
    //序列化Json
    function getFormJson(form) {
        var o = {};
        var a = form
        $.each(a, function () {
            if (o[this.name] !== undefined) {
                if (!o[this.name].push) {
                    o[this.name] = [o[this.name]];
                }
                o[this.name].push(this.value || '');
            } else {
                o[this.name] = this.value || '';
            }
        });
        return o;
    }
    //提交修改
    function submithuoform(){
        var serialize = $("#dataform").serializeArray();
        var chukuParmas=getFormJson(serialize);
        console.log(chukuParmas)
        $.ajax({ //更新和添加用同一个接口即可
            url:"/chuku/updateOrAdd",
            type:"POST",
            data: JSON.stringify(chukuParmas),
            contentType:"application/json;charset=UTF8",
            dataType:"json",
            success:function (res){
                if (res.success){
                    alert(res.msg);
                }
                else{
                    alert("操作失败!")
                }
            },
            error:function (){
                alert("莫名错误")
            }
        })

    }

    //出库
    function chu(){
        $("#dataform")[0].reset();
        $("#id").val(0)
        jump(3);
    }



    //供货管理
    function getculist() {
        $.ajax({
            url:"/utils/getculist",
            type:"GET",
            contentType:"application/json;charset=UTF8",
            dataType:"json",
            success:function (res){
                if (res.success){
                    var list=res.data;
                    showculist(list)
                }
                else{
                    alert("查询失败!")
                }
            },
            error:function (){

            }
        })

    }
    function editcu(id){
        $.ajax({
            url:"/utils/getCuById/"+id,
            type:"GET",
            contentType:"application/json;charset=UTF8",
            dataType:"json",
            success:function (res){
                if (res.success){
                    var data=res.data
                    $("#cuid").val(data.id);
                    $("#cuname").val(data.name);
                    $("#cuemail").val(data.email);
                    $("#cuphone").val(data.phone);
                    $("#cuaddr").val(data.addr);
                    jumpcu()
                }
                else{
                    alert("查询失败!")
                }
            },
            error:function (){
            }
        })
    }
    function delcu(id){
        $.ajax({
            url:"/utils/delCuById/"+id,
            type:"GET",
            contentType:"application/json;charset=UTF8",
            dataType:"json",
            success:function (res){
                alert(res.msg)
            },
            error:function (){
            }
        })
    }
    function showculist(list){
        $('#culist').empty();
        for(var i=0;i<list.length;i++) {
            var tr="<tr>\n" +
                "<td>"+list[i].id+"</td>\n" +
                "<td>"+list[i].name+"</td>\n" +
                "<td>"+list[i].email+"</td>\n" +
                "<td>"+list[i].phone+"</td>\n" +
                "<td>"+list[i].addr+"</td>\n" +
                "<td><button style='background-color: #55d455; ' onclick=\"editcu("+list[i].id+")\">修改</button></td>\n" +
                "<td><button style='background-color: red;color: black ' onclick=\"delcu("+list[i].id+")\">删除</button></td>\n" +
                "</tr>"
            console.log(tr)
            $("#culist").append(tr);
        }
    }
    //添加客户
    function addcu(){
        $("#dataform_cu")[0].reset();
        $("#cuid").val(0)
        jumpcu()
    }
    function jumpcu(){
        document.getElementById('all_light_cu');
        document.getElementById('contes_cu').style.display = 'block';
    }
    function cancelcu(){
        document.getElementById('contes_cu').style.display = 'none';
    }
    //提交修改客户
    function submitcuform(){
        var serialize = $("#dataform_cu").serializeArray();
        var cuParmas=getFormJson(serialize);
        console.log(cuParmas)
        $.ajax({ //更新和添加用同一个接口即可
            url:"/utils/cuupdateOrAdd",
            type:"POST",
            data: JSON.stringify(cuParmas),
            contentType:"application/json;charset=UTF8",
            dataType:"json",
            success:function (res){
                if (res.success){
                    alert(res.msg);
                }
                else{
                    alert("操作失败!")
                }
            },
            error:function (){
                alert("莫名错误")
            }
        })

    }
    //客户管理


    //修改
    function edit(id){
        $.ajax({
            url:"/chuku/getById/"+id,
            type:"GET",
            contentType:"application/json;charset=UTF8",
            dataType:"json",
            success:function (res){
                if (res.success){
                    var user=res.data
                    $("#id").val(user.id);
                    $("#sum").val(user.sum);
                    // $("#dept").val(user.dept.name+"-->id"+user.dept.id);
                    $("#sumPrice").val(user.sumPrice);
                    // $("#wid").val(user.wid+"-->id"+user.dept.id);
                    // $("#customer").val(user.customer.name+"-->id"+user.dept.id);

                }
                else{
                    alert("查询失败!")
                }
            },
            error:function (){
            }
        })

        jump(3);
    }

    //删除人员
    function delU(id) {

        $.ajax({
            url:"/chuku/del/"+id,
            type:"GET",
            contentType:"application/json;charset=UTF8",
            dataType:"json",
            success:function (res){
                if (res.success){
                    alert(res.msg)
                    location.reload();
                }
                else{
                    alert(res.msg)
                }
            },
            error:function (){

            }
        })
    }


    //展示入库信息列表
    function showList(list,sum,index,query){
        $('#newList').empty();
        for(var i=0;i<list.length;i++) {
            var tr="<tr>\n" +
                "<td>"+list[i].id+"</td>\n" +
                "<td>"+list[i].good.name+"</td>\n" +
                "<td>"+list[i].sum+"</td>\n" +
                "<td >"+list[i].status.attr+"</td>\n" +
                "<td>"+list[i].good.perPrice+"</td>\n" +
                "<td>"+list[i].totalPrice+"</td>\n" +
                "<td>"+list[i].wid+"</td>\n" +
                "<td >"+list[i].pass+"</td>\n" +
                "<td>"+list[i].customer.name+"</td>\n" +
                "<td>"+list[i].dept.name+"</td>\n" +
                "<td>"+list[i].updateTime+"</td>\n" +
                "<td><button style='background-color: #55d455 ' onclick=\"fatui("+list[i].id+")\">发起退货</button></td>\n" +
                "<td><button style='background-color: #55d455 ' onclick=\"fatui2("+list[i].id+")\">部分退货</button></td>\n" +
                "<td><button style='background-color: #55d455 ' onclick=\"edit("+list[i].id+")\">修改信息</button></td>\n" +
                "<td><button type='submit' style='background-color: #ff3948;color: black' onclick=\"delU("+list[i].id+")\">删除信息</button></td>\n" +
                "</tr>"
            console.log(tr)
            $("#newList").append(tr);
        }
        $('#pagination').empty();
        for(var i=1;i<=sum;i++){
            if(i==index)var li="<li><button style='color: red' onclick=\"gopage("+i+","+query+")\">"+i+"</button></li>";
            else var li="<li><button onclick=\"gopage("+i+","+query+")\">"+i+"</button></li>";
            $("#pagination").append(li);
        }
    }



    //退货
    function fatui(id){
        $.ajax({
            url:"/chuku/tuihuo/"+id,
            type:"GET",
            contentType:"application/json;charset=UTF8",
            dataType:"json",
            success:function (res){
                alert(res.msg)
                location.reload();
            },
            error:function (){
            }
        })
    }
    //部分退货
    function fatui2(id){
        var count=prompt("请输入退货数量")
        $.ajax({
            url:"/chuku/tuihuo2",
            type:"POST",
            data: '{"counts":"'+count+'","id":"'+id+'"}',
            contentType:"application/json;charset=UTF8",
            dataType:"json",
            success:function (res){
                alert(res.msg)
                location.reload();
            },
            error:function (){
            }
        })
    }
    function quxiaotuihuo(id) {
        $.ajax({
            url:"/ruku/quxiaotuihuo/"+id,
            type:"GET",
            contentType:"application/json;charset=UTF8",
            dataType:"json",
            success:function (res){
                alert(res.msg)
                location.reload()
            },
            error:function (){

            }
        })
    }
    function showtuihuolist(list) {
        $('#tuihuolist').empty();
        var hid='pointer-events: none;';
        for(var i=0;i<list.length;i++) {
            var tr="<tr>\n" +
                "<td>"+list[i].id+"</td>\n" +
                "<td>"+list[i].reId+"</td>\n" +
                "<td>"+list[i].status.attr+"</td>\n" +
                "<td>"+list[i].ispass+"</td>\n" +
                "<td>"+list[i].updateTime+"</td>\n" +
                "<td id='td-cnt"+list[i].id+"'>"+list[i].counts+"</td>\n" +
                "<td><button id='btn-qu"+list[i].id+"' style='background-color: red;color: black ' onclick=\"quxiaotuihuo("+list[i].id+")\">取消退货</button></td>\n" +
                "</tr>"
            $("#tuihuolist").append(tr);
            if (list[i].ispass==true){
                document.getElementById('btn-qu'+list[i].id+'').style.cssText=hid;//如果已经通过则不能取消退货
            }
            if (list[i].counts==-1){
                document.getElementById('td-cnt'+list[i].id+'').innerHTML="整单退货"
            }
        }
    }
    function gettuihuolist() {
        $.ajax({
            url:"/chuku/getTuiList",
            type:"GET",
            contentType:"application/json;charset=UTF8",
            dataType:"json",
            success:function (res){
                if (res.success){
                    var list=res.data;
                    showtuihuolist(list)
                }
                else{
                    alert("查询失败!")
                }
            },
            error:function (){

            }
        })

    }
    //去xx页面
    function gopage(i,query){
        // $('#newList').empty();
        pagination.currentPage=i;//修改当前页码
        if(query==0){
            query=''
        }
        $.ajax({
            url:"/chuku/getList",
            type:"POST",
            data:'{"currentPage":"'+pagination.currentPage+'","pageSize":"'+pagination.pageSize+'","queryMsg":"'+query+'"}',
            contentType:"application/json;charset=UTF8",
            dataType:"json",
            success:function (res){
                if (res.success){
                    var l=res.data.list//重新赋值
                    var sum=res.data.totalPage;//更新总页数
                    showList(l,sum,i,query)
                }
                else{
                    alert("查询失败!")
                }
            },
            error:function (){

            }
        })


    }
    function load(){
        gopage(1,null);
        gettuihuolist();
        getculist()
    }




</script>


</body>
</html>
